<?php

namespace app\logic\sms;

class SendSMS
{
    private $obj_model_name;
    private $str_module_name;
    private $str_id_name;

    public function __construct($str_module_name)
    {
        $this->str_module_name = $str_module_name;
        switch ($str_module_name) {
            case 'admin': // cms
                $this->obj_model_name = \app\model\AdminInfo::getInstance();
                $this->str_id_name = 'admin_id';
                break;
            case 'user': // 用户端
                $this->obj_model_name = \app\model\UserInfo::getInstance();
                $this->str_id_name = 'user_id';
                break;
            case 'courier': // 快递端
                $this->obj_model_name = \app\model\CourierInfo::getInstance();
                $this->str_id_name = 'courier_id';
                break;
            case 'stationpc': // 站点PC端
                $this->obj_model_name = \app\model\StationInfo::getInstance();
                $this->str_id_name = 'station_id';
                break;
            case 'stationapp': // 站点手机端
                $this->obj_model_name = \app\model\StationMemberInfo::getInstance();
                $this->str_id_name = 'station_member_id';
                break;
            default:
                return false;
        }
    }

    /**
     * 发送短信验证码(带手机号码)
     * @param $str_type
     * @param $str_mobile
     */
    public function sendSMSWithMobile($str_type, $str_mobile)
    {
        _toCompare(!in_array($str_type, ['login', 'forget', 'auth', 'bank_card', 'pay_password']), '===', true, 19023); // 短信类型错误

        _toValidate('mobile', $str_mobile, 11002); // 手机号码不正确

        // 使用验证 如果是登录或者忘记密码的前提都必须是用户存在 否者 不需要发送验证码
        // $arr_user_info = ModelUserSystem::getInstance()->checkIsSetUser($str_mobile);
        // _toCompare($arr_user_info, '===', false, 12003);

        $int_length = 4; // 默认发送四位验证码
        $result = SMS::getInstance()->sendSMS($str_type, $str_mobile, $this->str_module_name, $int_length);
        _toCompare($result, '===', false, 11003); // 短信发送失败

        _returnData(['passKey' => $result]);
    }
}
